package com.java.util;

/**
 * @desc
 * @version 2016年5月13日
 */
public class PriceUtil {
	/**
	 * 计算价格
	 * 总价=起始价5+省市区差价15 10 5 +重量*0.8
	 * @return
	 */
	public static String calPrice(String address, String toAddress, String weight) {
		float price = 5;
		String[] as = address.split("\\|");
		String[] ts = toAddress.split("\\|");
		for (int i = 0; i < as.length; i++){
			if (!as[i].equals(ts[i])){
				price += 5*(3-i);
				System.out.println(i);
				break;
			}
		}
		price += Float.valueOf(weight)*0.7;
		return String.valueOf(Math.ceil(price));
	}
	/**
	 * 计算价格
	 * 总价=省市区差价15 10 5 +重量*0.8
	 * @return
	 */
	public static String calPrice2(String address, String toAddress, String weight) {
		float price = 0;
		String[] as = address.split("\\|");
		String[] ts = toAddress.split("\\|");
		for (int i = 0; i < as.length; i++){
			if (!as[i].equals(ts[i])){
				price += 5*(3-i);
				System.out.println(i);
				break;
			}
		}
		price += Float.valueOf(weight)*0.8;
		return String.valueOf(Math.ceil(price));
	}
	
	
	public static void main(String[] args) {
		String price = PriceUtil.calPrice("福建省|福州市|鼓楼区", "福建省|福州市|鼓楼区", "20");
		System.out.println(price);
	}
}
